<template>
  <div class="home">
    <!-- 英雄区域 -->
    <section class="hero">
      <div class="hero-content">
        <h1>掌握Java编程的终极知识库</h1>
        <p>从基础语法到高级框架，一站式学习Java开发。包含教程、面试题、实战项目和可视化学习工具。</p>
        <div class="hero-btns">
          <a href="#" class="btn btn-primary" @click.prevent="goToDetail('java-basic')">开始学习 <i class="fas fa-arrow-right"></i></a>
          <a href="#features" class="btn btn-secondary">探索功能</a>
        </div>
      </div>

      <div class="hero-image">
        <svg viewBox="0 0 600 600" xmlns="http://www.w3.org/2000/svg">
          <circle cx="300" cy="300" r="200" fill="#4a6baf" opacity="0.1"/>
          <circle cx="350" cy="250" r="150" fill="#f47a60" opacity="0.1"/>
          <rect x="200" y="200" width="200" height="200" rx="20" fill="white" stroke="#4a6baf" stroke-width="3"/>
          <circle cx="300" cy="250" r="40" fill="#4a6baf" opacity="0.7"/>
          <rect x="220" y="320" width="160" height="20" rx="10" fill="#f47a60" opacity="0.8"/>
          <rect x="220" y="360" width="120" height="20" rx="10" fill="#4a6baf" opacity="0.5"/>
          <path d="M100 400 L300 150 L500 400 Z" fill="none" stroke="#4a6baf" stroke-width="3" stroke-dasharray="10,5"/>
          <circle cx="300" cy="150" r="15" fill="#f47a60"/>
        </svg>
      </div>
    </section>

    <!-- 功能展示 -->
    <section class="features" id="features">
      <div class="section-title">
        <h2>强大功能助力学习</h2>
        <p>Java知识库提供多种学习工具和资源，帮助您更高效地掌握Java编程</p>
      </div>

      <div class="features-grid">
        <div class="feature-card" v-for="feature in features" :key="feature.id">
          <div class="feature-icon">
            <i :class="feature.icon"></i>
          </div>
          <h3>{{ feature.title }}</h3>
          <p>{{ feature.desc }}</p>
        </div>
      </div>
    </section>

    <!-- 知识点分类 -->
    <section class="categories">
      <div class="section-title">
        <h2>Java知识体系</h2>
        <p>全面覆盖Java编程的各个知识领域</p>
      </div>

      <div class="categories-grid">
        <div class="category-card" v-for="category in knowledgeCategories" :key="category.id">
          <div class="category-header" :style="{ background: category.color }">
            <h3>{{ category.title }}</h3>
          </div>
          <div class="category-body">
            <ul>
              <li v-for="item in category.items" :key="item">
                <i class="fas fa-check-circle"></i> {{ item }}
              </li>
            </ul>
          </div>
          <a href="#" class="learn-more" @click.prevent="goToCategory(category.id)">
            探索内容 <i class="fas fa-arrow-right"></i>
          </a>
        </div>
      </div>
    </section>

    <!-- 学习路径 -->
    <section class="learning-path">
      <div class="section-title">
        <h2>高效学习路径</h2>
        <p>结构化学习路线，助您成为Java开发专家</p>
      </div>

      <div class="path-container">
        <div class="path-line"></div>
        
        <div class="path-step" v-for="(step, index) in learningSteps" :key="step.id">
          <div class="step-number">{{ index + 1 }}</div>
          <div class="step-content">
            <h3>{{ step.title }}</h3>
            <p>{{ step.desc }}</p>
          </div>
        </div>
      </div>
    </section>

    <!-- 资源推荐 -->
    <section class="resources">
      <div class="section-title">
        <h2>精选学习资源</h2>
        <p>优质书籍、教程和社区推荐</p>
      </div>

      <div class="resources-grid">
        <div class="resource-card" v-for="resource in resources" :key="resource.id">
          <div class="resource-img" :style="{ background: resource.gradient }">
            <i :class="resource.icon"></i>
          </div>
          <div class="resource-content">
            <h3>{{ resource.title }}</h3>
            <p>{{ resource.desc }}</p>
            <div class="resource-tags">
              <span class="tag" v-for="tag in resource.tags" :key="tag">{{ tag }}</span>
            </div>
            <a href="#" class="resource-link" @click.prevent="goToResource(resource.id)">
              {{ resource.linkText }} <i class="fas fa-external-link-alt"></i>
            </a>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 功能特性数据
const features = ref([
  {
    id: 'tutorial',
    title: '结构化教程',
    desc: '从基础到高级的完整教程体系，包含代码示例和实践练习',
    icon: 'fas fa-book-open'
  },
  {
    id: 'interactive',
    title: '交互式学习',
    desc: '在浏览器中直接编写和运行Java代码，实时查看结果',
    icon: 'fas fa-laptop-code'
  },
  {
    id: 'visualization',
    title: '可视化工具',
    desc: '数据结构动画、流程图和内存模型可视化，深入理解原理',
    icon: 'fas fa-project-diagram'
  },
  {
    id: 'interview',
    title: '面试题库',
    desc: '精选1000+Java面试题，包含详细解析和分类练习',
    icon: 'fas fa-file-alt'
  },
  {
    id: 'path',
    title: '学习路径',
    desc: '根据您的目标定制学习路线，从Java基础到架构师',
    icon: 'fas fa-road'
  },
  {
    id: 'project',
    title: '实战项目',
    desc: '真实项目案例教学，从电商系统到微服务架构',
    icon: 'fas fa-trophy'
  }
])

// 知识分类数据
const knowledgeCategories = ref([
  {
    id: 'java-basic',
    title: 'Java基础',
    color: '#4a6baf',
    items: ['语法基础', '面向对象', '异常处理', '集合框架', '泛型编程']
  },
  {
    id: 'java-advanced',
    title: 'Java高级',
    color: '#f47a60',
    items: ['多线程', '网络编程', 'IO/NIO', '反射机制', '注解']
  },
  {
    id: 'java-web',
    title: 'Java Web',
    color: '#3498db',
    items: ['Servlet/JSP', 'Spring框架', 'Spring Boot', '数据库访问', 'RESTful API']
  },
  {
    id: 'system-design',
    title: '系统设计',
    color: '#2ecc71',
    items: ['设计模式', '系统架构', '微服务', '性能优化', '高并发']
  }
])

// 学习路径步骤
const learningSteps = ref([
  {
    id: 'step1',
    title: 'Java基础',
    desc: '掌握Java核心语法、面向对象编程、集合框架和异常处理'
  },
  {
    id: 'step2',
    title: '数据库与SQL',
    desc: '学习关系型数据库设计、SQL语言和JDBC编程'
  },
  {
    id: 'step3',
    title: 'Java Web开发',
    desc: '掌握Servlet、JSP、MVC模式和Web应用开发'
  },
  {
    id: 'step4',
    title: 'Spring生态系统',
    desc: '深入学习Spring框架、Spring Boot和Spring Cloud'
  },
  {
    id: 'step5',
    title: '分布式系统',
    desc: '学习微服务架构、分布式缓存、消息队列和服务治理'
  },
  {
    id: 'step6',
    title: '系统设计与优化',
    desc: '掌握设计模式、高并发设计、性能优化和系统监控'
  }
])

// 学习资源数据
const resources = ref([
  {
    id: 'book1',
    title: '《Java核心技术》',
    desc: '最权威的Java学习指南，覆盖Java基础到高级特性',
    tags: ['书籍', '基础', '经典'],
    icon: 'fas fa-book',
    gradient: 'linear-gradient(135deg, #4a6baf, #6a8bd1)',
    linkText: '查看详情'
  },
  {
    id: 'tutorial1',
    title: 'Spring Boot实战教程',
    desc: '从零开始构建企业级应用的完整学习路径',
    tags: ['教程', 'Spring', '实战'],
    icon: 'fas fa-graduation-cap',
    gradient: 'linear-gradient(135deg, #f47a60, #f8a58b)',
    linkText: '开始学习'
  },
  {
    id: 'github1',
    title: '开源项目合集',
    desc: '精选Java开源项目，学习优秀代码实践',
    tags: ['开源', '项目', '实践'],
    icon: 'fab fa-github',
    gradient: 'linear-gradient(135deg, #2ecc71, #5dd99e)',
    linkText: '浏览项目'
  }
])

// 方法定义
const goToDetail = (id) => {
  if (id === 'java-basic') {
    router.push('/java-basic/syntax')
  } else {
    router.push(`/knowledge/${id}`)
  }
}

const goToCategory = (categoryId) => {
  if (categoryId === 'java-basic') {
    router.push('/java-basic/syntax')
  } else {
    router.push(`/category/${categoryId}`)
  }
}

const goToResource = (resourceId) => {
  router.push(`/resource/${resourceId}`)
}
</script>

<style scoped>
:root {
  --primary: #4a6baf;
  --secondary: #f47a60;
  --dark: #2c3e50;
  --light: #f8f9fa;
  --gray: #6c757d;
  --light-gray: #e9ecef;
  --border-radius: 12px;
  --box-shadow: 0 10px 30px rgba(0,0,0,0.1);
  --transition: all 0.3s ease;
}

.home {
  overflow-x: hidden;
}

/* 英雄区域 */
.hero {
  min-height: 100vh;
  display: flex;
  align-items: center;
  padding: 0 10%;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%);
}

.hero-content {
  max-width: 600px;
  z-index: 2;
}

.hero h1 {
  font-size: 3.5rem;
  font-weight: 800;
  margin-bottom: 20px;
  line-height: 1.2;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  font-size: 1.5rem;
  color: var(--gray);
  margin-bottom: 40px;
}

.hero-btns {
  display: flex;
  gap: 20px;
}

.btn {
  padding: 15px 30px;
  border-radius: 50px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #5a81d1);
  color: white;
  box-shadow: 0 10px 20px rgba(74, 107, 175, 0.3);
}

.btn-primary:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 30px rgba(74, 107, 175, 0.4);
}

.btn-secondary {
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-secondary:hover {
  background: rgba(74, 107, 175, 0.05);
  transform: translateY(-5px);
}

.hero-image {
  position: absolute;
  right: 5%;
  top: 50%;
  transform: translateY(-50%);
  width: 40%;
  max-width: 600px;
  z-index: 1;
  filter: drop-shadow(0 20px 30px rgba(0,0,0,0.2));
}

/* 功能展示 */
.features {
  padding: 100px 10%;
  background: white;
}

.section-title {
  text-align: center;
  margin-bottom: 60px;
}

.section-title h2 {
  font-size: 2.5rem;
  color: var(--primary);
  margin-bottom: 15px;
}

.section-title p {
  font-size: 1.2rem;
  color: var(--gray);
  max-width: 700px;
  margin: 0 auto;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 30px;
}

.feature-card {
  background: white;
  border-radius: var(--border-radius);
  padding: 40px 30px;
  text-align: center;
  box-shadow: var(--box-shadow);
  transition: var(--transition);
}

.feature-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}

.feature-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--primary), #5a81d1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 25px;
}

.feature-icon i {
  font-size: 36px;
  color: white;
}

.feature-card h3 {
  font-size: 24px;
  margin-bottom: 15px;
  color: var(--dark);
}

.feature-card p {
  color: var(--gray);
  font-size: 18px;
}

/* 知识点分类 */
.categories {
  padding: 100px 10%;
  background: linear-gradient(135deg, #f0f4ff 0%, #e6eeff 100%);
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 25px;
}

.category-card {
  background: white;
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--box-shadow);
  transition: var(--transition);
}

.category-card:hover {
  transform: translateY(-10px);
}

.category-header {
  background: var(--primary);
  color: white;
  padding: 20px;
  text-align: center;
}

.category-header h3 {
  font-size: 22px;
}

.category-body {
  padding: 20px;
}

.category-body ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.category-body li {
  padding: 10px 0;
  border-bottom: 1px solid var(--light-gray);
  display: flex;
  align-items: center;
}

.category-body li:last-child {
  border-bottom: none;
}

.category-body li i {
  color: var(--secondary);
  margin-right: 10px;
  font-size: 14px;
}

.learn-more {
  display: block;
  text-align: center;
  padding: 15px;
  background: rgba(74, 107, 175, 0.1);
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  transition: var(--transition);
}

.learn-more:hover {
  background: rgba(74, 107, 175, 0.2);
}

/* 学习路径 */
.learning-path {
  padding: 100px 10%;
  background: white;
}

.path-container {
  position: relative;
  max-width: 1000px;
  margin: 0 auto;
}

.path-step {
  background: white;
  border-radius: var(--border-radius);
  padding: 30px;
  margin-bottom: 40px;
  box-shadow: var(--box-shadow);
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
}

.path-step:nth-child(even) {
  margin-left: 100px;
}

.path-step:nth-child(odd) {
  margin-right: 100px;
}

.step-number {
  min-width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--primary), #5a81d1);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  margin-right: 30px;
}

.step-content h3 {
  font-size: 24px;
  margin-bottom: 10px;
  color: var(--primary);
}

.step-content p {
  color: var(--gray);
  font-size: 18px;
}

.path-line {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(to bottom, var(--primary), var(--secondary));
  transform: translateX(-50%);
  z-index: 1;
}

/* 资源推荐 */
.resources {
  padding: 100px 10%;
  background: linear-gradient(135deg, #f0f4ff 0%, #e6eeff 100%);
}

.resources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 30px;
}

.resource-card {
  background: white;
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--box-shadow);
  transition: var(--transition);
}

.resource-card:hover {
  transform: translateY(-10px);
}

.resource-img {
  height: 200px;
  background: linear-gradient(135deg, #4a6baf, #6a8bd1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.resource-img i {
  font-size: 80px;
  color: white;
  opacity: 0.8;
}

.resource-content {
  padding: 25px;
}

.resource-content h3 {
  font-size: 22px;
  margin-bottom: 15px;
  color: var(--dark);
}

.resource-content p {
  color: var(--gray);
  margin-bottom: 20px;
}

.resource-tags {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.tag {
  background: rgba(74, 107, 175, 0.1);
  color: var(--primary);
  padding: 5px 15px;
  border-radius: 50px;
  font-size: 14px;
}

.resource-link {
  display: inline-block;
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.resource-link i {
  margin-left: 5px;
  transition: var(--transition);
}

.resource-link:hover i {
  transform: translateX(5px);
}

/* 响应式设计 */
@media (max-width: 992px) {
  .hero {
    flex-direction: column;
    text-align: center;
    padding-top: 100px;
  }

  .hero-content {
    margin-bottom: 50px;
  }

  .hero-image {
    position: relative;
    right: auto;
    top: auto;
    transform: none;
    width: 80%;
    margin: 0 auto;
  }

  .hero-btns {
    justify-content: center;
  }

  .path-step:nth-child(even),
  .path-step:nth-child(odd) {
    margin-left: 0;
    margin-right: 0;
  }
}

@media (max-width: 768px) {
  .hero h1 {
    font-size: 2.5rem;
  }

  .hero p {
    font-size: 1.2rem;
  }

  .hero-btns {
    flex-direction: column;
    gap: 15px;
  }

  .btn {
    width: 100%;
  }
}
</style> 